<?php
    class AUtil{
        public static function getChildCate($cid){

            if(self::isLeafCate($cid)){
                return $cid;
            }
            $arr = array();
            $c = new Model_Category();
            $c -> parent_id = $cid;
            $set = $c -> getAllMatch();

            while(!$set -> isEnd()){

                $subcat = $set -> getNext();


                if( self:: isLeafCate( $subcat -> id)){
                    $arr[] = $subcat -> id;
                }else{
                    $_tmp = self:: getChildCate($subcat -> id);
                    $arr = array_merge($arr ,(array)$_tmp);
                }
            }
            return implode(',' , $arr);

        }

        public static function isLeafCate($cid){
            $c = new Model_Category();
            $c -> parent_id = $cid;
            $cnt = $c -> getTotalNums();
            if($cnt == 0)
                return true;
            return false; 
        }
        public static function getCountById($id){
            if($id == '')return 0;
            $leafCate = self::getChildCate($id);

            $sql = "select count(id) as count from service where category in ( $leafCate )";
            $cnt = Widget_Db::getInstance()->runCountSql($sql);

            return '('.$cnt.'个)';


        }

    }
?>
